package com.levi.juc.lock;

/**
 * 死锁  A拿着锁A想获取锁B，B拿着锁B想获取锁A
 * jps查看java进程
 * jstack pid  查看该java进程的堆栈信息
 */
public class DeadLock {
    public static void main(String[] args) {
        new Thread(new MyThread("lockA","lockB")).start();
        new Thread(new MyThread("lockB", "lockA")).start();
    }
}

class MyThread implements Runnable {
    private String LockA;
    private String LockB;

    public MyThread(String lockA, String lockB) {
        LockA = lockA;
        LockB = lockB;
    }

    @Override
    public void run() {
        synchronized (LockA) {

            System.out.println(Thread.currentThread().getName()+" LockA"+" >>get"+LockB);

            synchronized (LockB) {
                System.out.println(Thread.currentThread().getName()+" LockB"+" >>get"+LockA);
            }
        }
    }
}
